package cn.itrip.biz.service.impl;


import cn.itrip.beans.vo.biz.GetImg;
import cn.itrip.beans.vo.biz.ListQueryHotelRoomBed;
import cn.itrip.beans.vo.biz.ListQueryHotelRoomByHotel;
import cn.itrip.beans.vo.biz.ListQueryHotelRoomByHotelVo;
import cn.itrip.biz.service.IItripHotelRoomService;
import cn.itrip.common.DateUtil;
import cn.itrip.dao.ItripHotelRoomMapper;
import cn.itrip.dao.ItripHotelTempStoreMapper;
import cn.itrip.dao.ItripImageMapper;
import cn.itrip.dao.ItripLabelDicMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * 酒店房间表 服务实现类
 * </p>
 *
 * @author 滕召伟
 * @since 2020-02-27
 */
@Service
public class ItripHotelRoomServiceImpl implements IItripHotelRoomService {
    @Resource
    ItripHotelRoomMapper itripHotelRoomMapper;
    @Resource
    ItripLabelDicMapper itripLabelDicMapper;
    @Resource
    ItripImageMapper itripImageMapper;
    @Resource
    ItripHotelTempStoreMapper itripHotelTempStoreMapper;

    @Override
    public List<ListQueryHotelRoomByHotelVo> listQueryHotelRoomByHotel(ListQueryHotelRoomByHotel byHotel) {
        String start = DateUtil.TimeTZToDateString(byHotel.getStartDate());
        String end = DateUtil.TimeTZToDateString(byHotel.getEndDate());
        List<ListQueryHotelRoomByHotelVo> list = itripHotelRoomMapper.listQueryHotelRoomByHotel(byHotel);
        List<ListQueryHotelRoomByHotelVo> removeList = new ArrayList<>();
        for (ListQueryHotelRoomByHotelVo vo : list) {
            ListQueryHotelRoomByHotelVo hotel = new ListQueryHotelRoomByHotelVo(vo.getId(), vo.getHotelId(), start, end);
            Integer count = itripHotelTempStoreMapper.GetRoomStoreByTime(hotel);
            if (count > 0) {
                removeList.add(vo);
            }
        }
        if (removeList.size() > 0) {
            for (ListQueryHotelRoomByHotelVo room : removeList) {
                list.remove(room);
            }
        }
        return list;
    }

    @Override
    public List<ListQueryHotelRoomBed> listQueryHotelRoomBedById(Integer id) {
        return itripLabelDicMapper.listQueryHotelRoomBedById(id);
    }

    @Override
    public List<GetImg> GetImg(Integer hotelId) {
        return itripImageMapper.GetImgList(hotelId);
    }

}
